﻿using NSubstitute;
using Sai.Core;
using Sai.Core.Rules;
using Sai.Test.TestDataBuilders;
using Sai.Test.XUnit;
using Xunit;

namespace Sai.Test.Rules
{
    public class CheckTypeInterfaceChangesFacts
    {
        [Fact, TouchingFileSystemTest]
        public void Implementing_Internal_Interface_Is_Not_Flagged()
        {
            const string className = "Class1";
            const string namespaceName = "ClassLibrary1";

            var oldClassBuilder = CompilableClassBuilder.PublicClass()
                .Named(className);

            string oldCode = BoilerPlateCodeBuilder.BuildFor(namespaceName, oldClassBuilder);
            
            var interfaceClassBuilder = CompilableInterfaceBuilder.InternalInterface()
						.Named("InternalInterface");

            var newClassBuilder = CompilableClassBuilder.PublicClass()
                .Named(className)
                .Implementing("InternalInterface");

            string newCode = BoilerPlateCodeBuilder.BuildFor(namespaceName, new IBuildable[] { 
                            newClassBuilder,
                            interfaceClassBuilder 
            });

            IProductReleaseProject project = Mock.MinimalProject();

            TypeDifference diff = TypeDifferenceBuilder.Differences()
                .CodeWas(oldCode)
                .CodeIsNow(newCode)
                .CheckedUsing(new InterfacesAdded())
                .Build();

            Assert.False(diff.HasChanged);

            Assert.Null(diff.MethodsAdded);
            Assert.Null(diff.MethodsChanged);
            Assert.Null(diff.MethodsObsolete);
            Assert.Null(diff.MethodsRemoved);
        }

    }
}
